package com.tronsis.distribution.activity.me.coupons;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;

import com.tronsis.distribution.R;
import com.tronsis.distribution.activity.me.order.MyStockActivity;
import com.tronsis.distribution.bean.AskBuyBean;
import com.tronsis.distribution.bean.CouponBean;
import com.tronsis.distribution.biz.factory.OrderBizFactory;
import com.tronsis.distribution.http.Url;
import com.tronsis.distribution.util.StateUtil;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.http.UICallBack;
import com.tronsis.library.imageloader.ImageLoader;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CouponsUseActivity extends ToolBarBaseActivity {

    @BindView(R.id.iv_cover)
    ImageView mIvCover;
    @BindView(R.id.btn_submit_apply)
    Button mBtnSubmitApply;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coupons_use);
        ButterKnife.bind(this);
        setTitle(true, getString(R.string.coupons));

        CouponBean couponBean = (CouponBean) getIntent().getSerializableExtra("CouponBean");
        if (couponBean != null) {
            ImageLoader.display(mContext, Url.FILE_DOWNLOAD + couponBean.getCoverFid(), mIvCover);
        }
    }

    @OnClick(R.id.btn_submit_apply)
    void submitClick() {
        httpUseCoupons();
    }


    private void httpUseCoupons() {
        try {
            OrderBizFactory.createBiz().useCoupon(this, new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    dismissLoadingDialog();
                    String buyId = (String) data;
                    AskBuyBean askBuyBean = new AskBuyBean();
                    askBuyBean.setId(buyId);
                    askBuyBean.setState(StateUtil.MY_STOCK_ORDER_PAY);
//                    Intent intent = new Intent(mContext, OrderDetailActivity.class);
//                    intent.putExtra("AskBuyBean", askBuyBean);
//                    intent.setType("my");
                    Intent intent = new Intent(mContext, MyStockActivity.class);
                    startActivity(intent);
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();

                }
            });
        } catch (Exception e) {
            dismissLoadingDialog();
            e.printStackTrace();
        }
    }
}
